<?php

/**
 * This is the model class for table "channels".
 *
 * The followings are the available columns in table 'channels':
 * @property integer $id
 * @property integer $sequences
 * @property string $name
 * @property string $rule
 */
class Channel extends ActiveRecord {

	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Channel the static model class
	 */
	public static function model($className = __CLASS__) {
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName() {
		return 'channels';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules() {
		$rules = parent::rules();
		$rules[] = array(
			'sequence',
			'numerical',
			'integerOnly'=>true,
		);
		$rules[] = array(
			'sequence',
			'unique',
		);
		$rules[] = array(
			array(
				'name',
				'rule',
			),
			'length',
			'max'=>255,
		);
		$rules[] = array(
			array(
				'id',
				'sequence',
				'name',
				'rule',
				'createdAt',
				'updatedAt',
			),
			'safe',
			'on'=>'search',
		);
		$rules[] = array(
			array(
				'sequence',
				'name',
				'rule',
			),
			'required',
			'on'=>'insert, update',
		);
		return $rules;
	}

	/**
	 * @return array relational rules.
	 */
	public function relations() {
		$relations = parent::relations();
		return $relations;
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels() {
		return array(
			'id'=>'ID',
			'sequence'=>'Sequence',
			'name'=>'Name',
			'rule'=>'Rule',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models
	 *   based on the search/filter conditions.
	 */
	public function search() {
		$criteria = new CDbCriteria;
		$criteria->compare('id', $this->id);
		$criteria->compare('sequence', $this->sequence);
		$criteria->compare('name', $this->name, true);
		$criteria->compare('rule', $this->rule, true);
		$criteria->compare('createdAt', $this->createdAt, true);
		$criteria->compare('updatedAt', $this->updatedAt, true);
		return new CActiveDataProvider($this, array('criteria'=>$criteria));
	}
	
	public function init() {
		parent::init();
		$this->rule = 'return $value;';
	}

}